package com.aiit.service.impl;

import com.aiit.dto.TeaOrderDTO;
import com.aiit.entity.TeaOrder;
import com.aiit.mapper.OrderMapper;
import com.aiit.service.OrderService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.annotation.WebServlet;
import java.time.LocalDateTime;

@Service
@WebServlet("/verifyCode")
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public boolean existsByOrderId(Long orderId) {
        return false;
    }

    @Override
    public Page<TeaOrder> adminOrder(TeaOrderDTO teaOrderDTO) {

        Page<TeaOrder> orders = orderMapper.getByTeaOrderDetail(teaOrderDTO);


        return orders;
    }

    public void updatePayment(TeaOrderDTO teaOrderDTO) {
        TeaOrder teaOrder = new TeaOrder();

        Long id = teaOrderDTO.getId();
        teaOrder.setDispatchTime(LocalDateTime.now());
        teaOrder.setId(id);
        orderMapper.getById(id);
        orderMapper.payment(teaOrder);

    }

    @Override
    public void updateDeliver(TeaOrderDTO teaOrderDTO) {
        TeaOrder teaOrder = new TeaOrder();

        Long id = teaOrderDTO.getId();
        teaOrder.setDeliveryTime(LocalDateTime.now());
        teaOrder.setId(id);
        orderMapper.getByIdDeliver(id);
        orderMapper.deliver(teaOrder);
    }

}
